class LinkedStack {
    private Node top; //# reference to the top node

private int size; //# number of elements in the stack


public LinkedStack( ) { //# Initialize the stack

top = null;

size = 0;

}
public int size( ) { //# Returns the current stack size

return size;

}
public boolean isEmpty( ) { //# Returns true if the stack is empty
if (top == null)
return true;
return false;
}
public Object top( ) throws StackException { // Return the top stack // element
if (isEmpty( ))
throw new StackException("Stack is empty.");
return top.getElement( );
}
public void push(Object obj) { // Push a new object on the stack

Node n = new Node( );

n.setElement(obj);

n.setNext(top);

top = n;

size++;

}
public Object pop( ) throws StackException { // Pop off the top stack element

Object temp;

if (isEmpty( ))

throw new StackException("Stack is empty.");

temp = top.getElement( );

top = top.getNext( ); // link-out the top node

size--;

return temp;

}
public void clearStack() throws StackException{
while(top!=null)
    pop(); // keep popping while top does not equal null. 
}


public void next() {
     top = top.getNext();
     
   }

public boolean search(Object value,int stackSize,LinkedStack s) throws StackException{
    boolean result = false;
    for(int i=0;i<stackSize;i++){
        if(top.getElement()==value)
            return result=true;
        else if(top.getElement()!=value){
            
        }
    }
    return result=false;
    
    //
    // clearly not working..... any suggestion how to actually get this working?
}


}

